using Microsoft.AspNetCore.Mvc;
using ZR.Model.System;
using ZR.Model.System.Dto;
using ZR.Service.System;
using ZR.Admin.WebApi.Filters;

//创建时间：2024-12-19
namespace ZR.Admin.WebApi.Controllers.System
{
    /// <summary>
    /// 报警配置管理
    /// </summary>
    [Verify]
    [Route("system/config")]
    public class ConfigController : BaseController
    {
        /// <summary>
        /// 报警配置接口
        /// </summary>
        private readonly IConfigService _configService;

        public ConfigController(IConfigService configService)
        {
            _configService = configService;
        }

        /// <summary>
        /// 查询报警配置信息
        /// </summary>
        /// <returns></returns>
        [HttpGet("getConfig")]
        public IActionResult GetConfig()
        {
            var response = _configService.GetConfig();

            if (response == null)
            {
                return SUCCESS(new ConfigDto());
            }

            var info = response.Adapt<ConfigDto>();
            return SUCCESS(info);
        }

        /// <summary>
        /// 更新报警配置
        /// </summary>
        /// <returns></returns>
        [HttpPut("putConfig")]
        [Log(Title = "报警配置", BusinessType = BusinessType.UPDATE)]
        public IActionResult UpdateConfig([FromBody] ConfigDto parm)
        {
            var modal = parm.Adapt<Config>().ToUpdate(HttpContext);
            var response = _configService.UpdateConfig(modal);

            return ToResponse(response);
        }

        /// <summary>
        /// 初始化报警配置
        /// </summary>
        /// <returns></returns>
        [HttpPost("init")]
        [Log(Title = "初始化报警配置", BusinessType = BusinessType.INSERT)]
        public IActionResult InitConfig([FromBody] ConfigDto parm)
        {
            var modal = parm.Adapt<Config>().ToCreate(HttpContext);
            var response = _configService.InitConfig(modal);

            return SUCCESS(response);
        }
    }
}

